package api

import (
	"api-server/basic/config"
	"api-server/common/model"
	"api-server/handler/request"
	"api-server/until"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
)

func LoginAndRegister(c *gin.Context) {
	var req request.LoginAndRegisterReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10001,
			"msg":  "验证失败",
			"date": err.Error(),
		})
		return
	}
	var user model.User
	err := config.DB.Where("model").Find(&user).Error
	if err != nil {
		log.Printf("用户不存在")
	}
	newUser := model.User{
		Mobile:   req.Mobile,
		Password: req.Password,
	}
	err = config.DB.Create(&newUser).Error
	if err != nil {
		log.Println("注册失败")
	}
	if req.Password != newUser.Password {
		log.Println("用户密码错误，请重新输入")
	}
	until.JWTAuth("2211A")
	token := until.JWTAuth("2211A")
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "登录成功",
		"date": token,
	})
}

func SendSms(c *gin.Context) {
	var req model.User
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{})
	}
}

func SmsLogin(c *gin.Context) {

}
